package com.RedRiver.hospitalsystem.finance_service.common;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class WoniuxyBeanCopyUtil {

    public static <T> T copyone(Object source,Class<T> clazz){
        T t = null;
        try {
             t =clazz.newInstance();
            BeanUtils.copyProperties(source,t);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return t;
    }



    public static <T>List<T> copyList(List source, Class<T> clazz){
        ArrayList arrayList = new ArrayList();
        try {
            for (Object o : source) {
                T t =clazz.newInstance();
                BeanUtils.copyProperties(o,t);
                arrayList.add(t);
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return arrayList;
    }


}
